
cc.Class({
    extends: cc.Component,

    properties: {
        speedX:{
            default:200,
            type:cc.Integer,
        }
    },

    start() {
         this.poolNode = cc.find('Canvas/role');
         this.R_Width = cc.winSize.width * 0.5;
         this.L_Width = cc.winSize.width * -0.5;
         this.roleScaleX = this.poolNode.scaleX; 
    },

    show:function(){
        this.node.active = true;
    },
    hide:function(){
        this.node.active = false;
    },
    update (dt) {
        const dgScaleX = Math.abs(this.node.scaleX);
        var dg_x = this.speedX * dt;
        if (this.roleScaleX == 1) {
            this.node.scaleX = dgScaleX;
            this.node.x += dg_x; 
        }else if (this.roleScaleX == -1) {
            this.node.scaleX = -dgScaleX;
            this.node.x += -dg_x ;
        }
      

        if (this.node.x >= this.R_Width || this.node.x <= this.L_Width) {
            this.node.removeFromParent();
            this.hide();
            console.log("移除成功");
        }
    },
});
